<?php

// Si le fichier de qui dÔøΩfinie les constantes n'a pas encore ÔøΩtÔøΩ appelÔøΩ on le charge
if (!defined('CONFIGURATION_FILE_LOADED'))
    include( 'includes/configuration_include.php');
include( 'includes/regions.php');
include( 'includes/id_regions.php');

if($erreur==1)
{$erreur =0;}
include( PATH_VIEWS . 'works_view.php');
include( PATH_MODELS . 'works_model.php');

$bdd = model_db_connexion();

$details = $_GET['details'];


    if ($_GET['details'] and is_numeric($details)) {
        $req = $bdd->query('SELECT id_work FROM works WHERE id_work = ' . $details . '');
    $count = $req->rowcount();
    }


    if (isset($_GET['details']) && $_GET['details'] >= 0 && $count == 1) {
        if (is_numeric($details)) {
        if (isset($_POST['like']) && isset($_POST['work'])) {
            add_like($bdd, $_POST['work'], $_POST['like']);
        }

        $details = $_GET['details'];
        $req = model_one_work($bdd, $details);

        while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) {
            $work = $donnees['id_work'];
            $like = $donnees['work_like'];
            $user_name = $donnees['user_name'];
            $user_surname = $donnees['user_surname'];
            $work_name = $donnees['work_name'];
            $work_description = $donnees['work_description'];
            $id_work = $donnees['id_work'];
            $type_img = $donnees['img_type'];
            $type_img2 = $donnees['img_type2'];
            $id_autor = $donnees['user_id'];
            $str = printOneWork($like, $user_surname, $user_name, $work_name, $work_description, $work, $id_work, $type_img, $type_img2, $id_autor);
            echo $str . "\n";

            include( PATH_CONTROLLERS . 'comments_controller.php');
        }
        
} else { $erreur =1;
    echo '<span class="template_span">Cette page n\'existe pas !</span>';
}
    } elseif (isset($_GET['region']) && $_GET['region'] >= 0) {
        if (test_region($_GET['region']) == 0) {
            $region = $_GET['region'];
            $region = regionsjsTophp($region);
            $region_id = id_region($region);
            presentation_region($region);
            $req = select_one_region($bdd, $region_id);
            while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) {
                $i = 0;
                if ($i == 0) {
                    
                }
                $i++;
                $work = $donnees['id_work'];
                $user_name = $donnees['user_name'];
                $user_surname = $donnees['user_surname'];
                $work_name = $donnees['work_name'];
                $work_description = $donnees['work_description'];
                $id_work = $donnees['id_work'];
                $type_img = $donnees['img_type'];
                $str = printWorksRegion($work_name, $work, $id_work, $type_img);
            }
        } else {
            echo '<span class="template_span">Cette page n\'existe pas !</span>';
            $erreur =1;
        }
    } else {
if($erreur == 0){
        $str = printWorks();
}else{echo'erreur';}
        echo $str . "\n";
    }
?>
<script type="text/javascript">


                            
    function envoi_form($user_id){
        var w = $user_id;
               
    } 

</script>
<?php

function test_region($region) {
    $i = 0;
    $a = 1;
    while ($i < 21) {
        if (regions_js($i) == $region) {
            $a = 0;
        }
        $i++;
    }
    return $a;
}
?>